import { Meta, ArgsTable, Canvas, Story, Markdown } from '@storybook/addon-docs';
import { useArgs } from '@storybook/client-api';
import { Input } from '@zendeskgarden/react-forms';
import { InputStory } from './stories/InputStory';
import { commonArgs, commonArgTypes, fieldSubcomponents } from './stories/common';
import README from '../README.md';

<Meta
  title="Packages/Forms/Input"
  component={Input}
  subcomponents={{ ...fieldSubcomponents }}
  args={{
    ...commonArgs
  }}
  argTypes={{
    /* ensures the `validation` story arg for the `Input` component is not overriden */
    ...{ ...commonArgTypes, validation: {} },
    disabled: { control: 'boolean' },
    readOnly: { control: 'boolean' },
    placeholder: { control: 'text' },
    type: {
      control: {
        type: 'select'
      },
      options: [
        'date',
        'datetime-local',
        'email',
        'month',
        'number',
        'password',
        'search',
        'tel',
        'text',
        'time',
        'url',
        'week'
      ]
    }
  }}
  parameters={{
    design: {
      allowFullscreen: true,
      type: 'figma',
      url: 'https://www.figma.com/file/6g87L4FdKZTA3knt3Rsfdx/Garden?node-id=103%3A20266'
    }
  }}
/>

# API

<ArgsTable />

# Demo

## Uncontrolled

<Canvas>
  <Story name="Uncontrolled" args={{ placeholder: 'Placeholder' }}>
    {args => <InputStory {...args} />}
  </Story>
</Canvas>

## Controlled

<Canvas>
  <Story name="Controlled" args={{ value: 'Value' }}>
    {args => {
      const updateArgs = useArgs()[1];
      const handleChange = event => updateArgs({ value: event.target.value });
      return <InputStory {...args} onChange={handleChange} />;
    }}
  </Story>
</Canvas>

<Markdown>{README}</Markdown>
